package com.luck.emp.payment.web;

import org.apache.commons.lang.StringUtils;

import com.luck.emp.entity.EmpTPayment;
import com.luck.emp.payment.logic.IPaymentLogic;
import com.luck.emp.payment.qry.PaymentQry;
import com.luck.pf.common.entity.UserBean;
import com.luck.pf.framework.action.BaseActionSupport;
import com.luck.pf.util.ObjectUtil;
import com.luck.pf.util.Page;

/**
 * 说明:ACTION类 Copyright: Copyright (c) 2011 深圳**科技
 * 
 * @author
 * 
 */
public class PaymentAction extends BaseActionSupport {
	/**
	 * 逻辑处理类
	 */
	IPaymentLogic paymentLogic;
	/**
	 * 查询对象
	 */
	PaymentQry qry;
	/**
	 * 分页对象
	 **/
	Page page;
	/**
	 * 实体类
	 */
	EmpTPayment entity;

	/**
	 * 列表
	 */
	public String list() throws Exception {
		UserBean userInfo = super.getUserInfo();

		if (StringUtils.isNotBlank(super.qryHex)) {
			qry = (PaymentQry) ObjectUtil.getObjectFromHex(qryHex);
		}
		if (qry == null) {
			qry = new PaymentQry();
		}
		qry.setUserInfo(userInfo);
		page = paymentLogic.findPaymentPage(qry, Page.class);
		return "list";
	}

	/**
	 * 新增
	 **/
	public String toAdd() throws Exception {
		UserBean userInfo = super.getUserInfo();
		entity = new EmpTPayment();
		super.event = "ADD";
		super.title = "新增缴费管理";
		return "edit";
	}
	/**
	 * 修改动作
	 **/
	public String edit() throws Exception {
		UserBean userInfo = super.getUserInfo();
		if ("ADD".equals(super.event)) {
			// 新增操作
			entity.setId(null);
			paymentLogic.savePayment(userInfo, entity);
		} else if ("EDIT".equals(super.event)) {
			// 修改操作
			EmpTPayment db = paymentLogic
					.get(EmpTPayment.class, entity.getId());
			super.copyProperties(db, entity);
			paymentLogic.savePayment(userInfo, db);
		}
		super.redirectUrl = "/emp/payment_list.action";
		return super.GLOBAL_SUCCESS;
	}


	/**
	 * 修改
	 **/
	public String view() throws Exception {
		UserBean userInfo = super.getUserInfo();
		entity = paymentLogic.get(EmpTPayment.class, entity.getId());
		super.title = "缴费管理详细信息";
		return "view";
	}

	public PaymentQry getQry() {
		return this.qry;
	}

	public void setQry(PaymentQry qry) {
		this.qry = qry;
	}

	public IPaymentLogic getPaymentLogic() {
		return this.paymentLogic;
	}

	public void setPaymentLogic(IPaymentLogic paymentLogic) {
		this.paymentLogic = paymentLogic;
	}

	public Page getPage() {
		return this.page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public EmpTPayment getEntity() {
		return entity;
	}

	public void setEntity(EmpTPayment entity) {
		this.entity = entity;
	}
}